<template>
	<!-- 拒绝退货 & 修改理由 弹窗 -->
	<view class="item-info" :class="openShow === 0 ? 'none' : openShow === 1 ? 'show' : ''">
		<view class="cate-content">
			<view class="item-fixed-top">
				<view class="title">{{title}}</view>
				<view class="close" @click="show">
					<image src="../../static/images/close.png" mode="scaleToFill"></image>
				</view>
			</view>
			<view class="cate-list">
				<view class="txt-box">
					<view class="txt-v-1">
						<text class="txt-1">{{txt1}}</text>
						<text class="txt-1">{{txt1Value}}</text>
					</view>
					<view class="txt-v-1">
						<text class="txt-1">{{txt2}}</text>
						<text class="txt-1">{{txt2Value}}</text>
					</view>
				</view>
				<input class="input-value" 
					:value="inputValue" 
					:placeholder="tip"
					type="number"
					@input="inputHandler" />
				<view class="btn" @click="sure">{{sureTxt}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import staticConst from "../../js/const/StaticConst.js";
	import util from '../../js/util/Util.js';
	import config from "../../js/conf/Config.js";
	
	import lang from "../../js/conf/Lang.js";
	import https from "../../js/https/Https.js";
	
	
	export default {
		data() {
			return {
				title : "",
				txt1 : "",
				txt1Value : "",
				txt2 : "",
				txt2Value : "",
				tip : "",
				
				sureTxt : lang.confirm,
				
				inputValue:"",
				
				openShow : 0,
				callBack:null,
				
				act:0,
				countObj:null,
				windType: 1,//1:销售（默认）2：采购
			};
		},
		methods: {
			
			show(type,act,data,wType = 1) 
			{
				let timer = type === 'show' ? 10 : 200;
				let state = type === 'show' ? 1 : 0;
				this.openShow = 2;
				setTimeout(() => {
					this.openShow = state;
				}, timer);
				if(!type)return;
				this.inputValue = "";
				this.act = act;
				this.countObj = data;
				this.windType = wType;
				this.setData(act,data);
			},
			
			setData(act,data)
			{
				if(act == 1)
				{
					this.title = lang.receiptAct.zdzkTitTxt;//:"整单折扣",
					this.txt1 = lang.receiptAct.curZkTxt;//:"当前折扣:",
					this.txt1Value = data.discount + "%";
					this.txt2 = "";
					this.txt2Value = "";
					this.tip = lang.receiptAct.tipInputTxt;//:"输入折扣百分比",
				}
				else if(act == 2)
				{
					this.title = lang.receiptAct.yhmlTitTxt;//:"优惠抹零",
					this.txt1 = lang.receiptAct.ddyjTxt;//:"订单原价:",
					this.txt1Value = data.amountTotle;
					this.txt2 = lang.receiptAct.dqjgTxt;//:"当前价格:",
					this.txt2Value = data.totalPrice;
					this.tip = lang.receiptAct.tipMlInputTxt;//:"请输入抹零后的价格",
				}
			},
			
			inputHandler(event)
			{
				this.inputValue = event.target.value;
				if(this.act == 2)
				{
					// if(this.inputValue < 0 || this.inputValue > 100)
					// {
					// 	this.inputValue = 100;  //amount  discount_r zero
					// 	this.$msg({title:lang.receiptAct.inputTipTxt});
					// }
					// console.log(this.countObj,this.countObj.amountTotle);
					// console.log(this.inputValue > this.countObj.amountTotle);
					if(Number(this.inputValue) > Number(this.countObj.amountTotle))
					{
						this.inputValue = this.countObj.amountTotle;
						this.$msg({title:lang.receiptAct.ZeroErrTipTxt});
						return;
					}
				}
			},
			
			sure()
			{
				this.show();
				this.discountAndZeroAct();
			},
			
			/****折扣***/
			discountAndZeroAct()
			{
				let that = this;
				let param = {};
				param.amount = this.countObj.amountTotle;
				if(this.act == 1)
				{
					param.discount_r = this.inputValue;
				}
				else if(this.act == 2)
				{
					param.zero = this.inputValue;
				}
				param.amount_fee = this.countObj.amountFee;
				if(this.windType == 1)//销售
					https.orderCount(param,back);
				else if(this.windType == 2)//采购
					https.cgOrderCount(param,back);
				function back(data)
				{
					if(!data)return;
					if(data.status  == 1)
					{
						if(!data.data)return;
						data = data.data;
						that.countObj.totalPrice = data.amount;//总价
						that.countObj.amountTotle= data.amount_p;//原价
						that.countObj.discount = util.getInt(data.discount_r);//折扣 
						that.countObj.preferential = data.discount;//优惠
						that.countObj.amountZero = data.amount_zero //抹零后价格
						that.countObj.netReceiVal = data.amount_od; //输入价格初始
						that.countObj.amountOrderPrice = data.amount_od;//(订单折后价+费用)
					}
				}
			}
		},
	}
</script>
<style lang="scss">
	.mask {
		display: flex;
		align-items: flex-end;
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0, 0, 0, 0);
		z-index: 9999;
		transition: 0.3s;
		.mask-content {
			width: 100%;
			max-height: 250px;
			background: #f3f3f3;
			transform: translateY(100%);
			transition: 0.3s;
			.item
			{
				border-bottom: 1px solid #ECECEC;
				padding: 10px 20px;
			}
			.active
			{
				color: #3388FF;
			}
		}
		&.none {
			display: none;
		}
		&.show {
			background: rgba(0, 0, 0, 0.4);
			.mask-content {
				transform: translateY(0);
			}
		}
	}
	.item-info {
		position: fixed;
		z-index: 999;
		left: 0;
		top: 0;
		bottom: 0;
		width: 100%;
		background: #FFF;
		transition: 0.3s;
		overflow-y: hidden;
		display: flex;
		align-items: center;
		justify-content: center;
		.cate-content {
			border-radius: 6px;
			overflow: hidden;
			width: 300px;
			height: 200px;
			background: #F8F8F8;
			float: right;
			transform: translateY(-100%);
			transition: 0.3s;
			position: relative;
			.item-fixed-top
			{
				height: 50px;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 14px;
				border-bottom: 1px solid #ECECEC;
				.title
				{
					font-size: 18px;
				}
				.close
				{
					position: absolute;
					right: 5px;
					top: 12px;
					width: 32px;
					height: 32px;
					text-align: center;
					cursor: pointer;
					image
					{
						width: 14px;
						height: 14px;
					}
				}
			}
		}
	
		&.none {
			display: none;
		}
		&.show {
			background: rgba(0, 0, 0, 0.3);
			.cate-content {
				transform: translateY(0);
			}
		}
	}
	.bg-color
	{
		background: #E6E6E6;
		padding: 10px;
	}
	.cate-list
	{
		.txt-box
		{
			padding: 10px;
			color: #666;
			display: flex;
			.txt-v-1
			{
				width: 50%;
				
			}
		}
		
		.input-value
		{
			padding: 10px;
		}
		
		.btn
		{
			cursor: pointer;
			width: 100%;
			height: 40px;
			line-height: 40px;
			text-align: center;
			color: #fff;
			background-color: #3388ff;
			position: absolute;
			font-size: 18px;
			bottom: 0;
		}
		.btn:active
		{
			background-color: #3285fa;
		}
		.btn:hover
		{
			background-color: #3285fa;
		}
	}
</style>